package com.huike.game.Activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.huike.game.R;

import androidx.appcompat.app.AppCompatActivity;

import static com.huike.game.R.drawable.setting;

public class GameActivity1 extends AppCompatActivity {

    private ImageView iv_game1_image;
    private ImageView ivLeftImage;
    private TextView tvLeftText;
    private ImageView ivRigthImage;
    private TextView tvRightText;
    private TextView tvContentName;
    private Button bt_game1_main;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game1);

        initTitle();

//        通过判断缓存实现是否第一次打开软件
        SharedPreferences page = getSharedPreferences("page", MODE_PRIVATE);
        boolean isPage = page.getBoolean("isPage", false);
        if(isPage){
//            这里通过改变背景 标识跳转页面
            iv_game1_image.setImageResource(R.drawable.back);
            bt_game1_main.setVisibility(View.VISIBLE);
        }else{
            bt_game1_main.setVisibility(View.GONE);
            SharedPreferences onPage = getSharedPreferences("page", MODE_PRIVATE);
            onPage.edit().putBoolean("isPage",true).commit();
        }

    }

    private void initTitle() {
        ivLeftImage = (ImageView) findViewById(R.id.iv_left_image);
        tvLeftText = (TextView) findViewById(R.id.tv_left_text);
        ivRigthImage = (ImageView) findViewById(R.id.iv_rigth_image);
        tvRightText = (TextView) findViewById(R.id.tv_right_text);
        tvContentName = (TextView) findViewById(R.id.tv_content_title);
        iv_game1_image =findViewById(R.id.iv_game1_image);
        bt_game1_main =findViewById(R.id.bt_game1_main);

        ivLeftImage.setVisibility(View.GONE);
        tvLeftText.setVisibility(View.GONE);

        tvContentName.setText("用户登陆");

        ivRigthImage.setImageResource(setting);
        tvRightText.setText("网络设置");
    }

    public void clear(View v){

        SharedPreferences sp = getSharedPreferences("page", MODE_PRIVATE);
        sp.edit().clear().commit();

        Toast.makeText(this, "成功！", Toast.LENGTH_SHORT).show();

    }

}
